﻿using FlyHorse.LIMS.IBLL;
using FlyHorse.LIMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FlyHorse.LIMS.BLL
{
    public partial class SysReportTypeBll : BaseBll<SysReportType>, ISysReportTypeBll
    {

        public SysReportType EditSysReportType(string reportTypeID, List<TestItem> testItems)
        {
            using (OJCB4Entities db =new OJCB4Entities())
            {
                SysReportType type = db.Set<SysReportType>().Where(m => m.SysReportTypeID == reportTypeID).First();
                List<TestItem> testItemList = new List<TestItem>();
                foreach (var item in type.TestItems)
                {
                    testItemList.Add(item);
                }
                foreach (var testItem in testItemList)
                {
                    type.TestItems.Remove(testItem);
                }
                db.SaveChanges();
                
                foreach (var item in testItems)
                {
                    TestItem testItem = db.TestItems.Find(item.TestItemID);
                    type.TestItems.Add(testItem);
                }
                //db.Entry<SysReportType>(type).State = System.Data.Entity.EntityState.Modified;
                int count = db.SaveChanges();
                if (count > 0)
                {
                    return type;
                }
                else
                {
                    return null;
                }
            }
        }
    }
}
